<?php

	require_once(dirname(__FILE__)."/../core/safeParam.php");

	if($_REQUEST['action'] == $lang["password_send_button"]){
		$results_user = $database->select("SELECT * FROM users where email = '".$_POST['email']."'");
  		if($results_user == false){
    		$error .= $lang["password_user_not_registered"];
  		} else {
  			$passwordResetEmail = new Mail; // create the mail
    		
    		//email address 
    		$emailTo = $results_user[0]['email'];
    		
    		$password = $passwordResetEmail ->Mail_Password_Generator();
    		//Password update
    		$param = "password='$password[1]'"; 
    		$condition ="email='$emailTo'";
    		$database->update("users",$param,$condition);
      	
      	// Activation time update 
    		$dateTime = date('Y-m-d H:i:s');
    		$dateTime = strtotime($dateTime)+ 2*(60*60); 
    		$dateTime = date('Y-m-d H:i:s',$dateTime);
    
    		$param = "activation_time='$dateTime'";
    		$database->update("users",$param,$condition);
    		
    		//Sending mail 
    		$passwordResetEmail ->From (ADMIN_EMAIL);
    		$passwordResetEmail ->To ($emailTo);
    		$passwordResetEmail ->Cc (ADMIN_EMAIL);
    
    		$passwordResetEmail ->Subject ($lang["password_email_subject"]." ".SITE_NAME);    
    		$passwordResetEmail ->Body ($lang["password_email_body"]."&nbsp;$password[0]<br><a href=\"$siteroot\">$siteroot</a>");  // set the body  
    		$passwordResetEmail ->Priority (1);  // set the priority to Low  
    		$passwordResetEmail ->Send ();  // send the mail

    		$success .= $lang["password_email_success"]." ".$results_user[0]['email'];  
  		}
	}

	$smarty->assign('success',$success);
	$smarty->assign('error',$error);

?>